package adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.sxpjyy.monkey.mobilenurse.R;

import java.util.List;

/**
 * Created by Monkey on 2017/3/8.
 * 病人详细界面按钮适配器
 */

public class BuzRecyclerAdapter extends Adapter<BuzRecyclerAdapter.ViewHolder> implements View.OnClickListener {

    private Context mContext;
    private List<String> buttonText;
    private List<Integer> buttonImage;

    private OnRecyclerViewItemClickListener mOnItemClickListener = null;

    public interface OnRecyclerViewItemClickListener {
        void onItemClick(View view, String data);
    }


    public BuzRecyclerAdapter(Context context) {
        mContext = context;
    }

    public void setButtonText(List<String> list) {
        this.buttonText = list;
    }

    public void setButtonImage(List<Integer> buttonImage) {
        this.buttonImage = buttonImage;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_button, parent, false);
        view.setOnClickListener(this);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.itemView.setTag(buttonText.get(position));
        holder.button_text.setText(buttonText.get(position));
        holder.button_image.setBackgroundResource(buttonImage.get(position));
    }

    @Override
    public int getItemCount() {
        if (buttonText != null && buttonText.size() > 0) {
            return buttonText.size();
        }
        return 0;
    }

    public int getPosition() {
        return -1;
    }

    @Override
    public void onClick(View view) {
        if (mOnItemClickListener != null) {
            mOnItemClickListener.onItemClick(view, (String) view.getTag());
        }
    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView button_image;
        TextView button_text;

        ViewHolder(View itemView) {
            super(itemView);
            button_image = (ImageView) itemView.findViewById(R.id.button_icon);
            button_text = (TextView) itemView.findViewById(R.id.button_text);
        }
    }
}
